home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / bgiclip.com / CLIP.DOC < prev    next >
Encoding:
Text File  |  1990-11-07  |  12.1 KB  |  283 lines

  1. ===========================================================================
  2.  
  3.                                     CLIP
  4.  
  5.                              by Peter Donnelly
  6.                               1301 Ryan Street
  7.                                 Victoria BC
  8.                                Canada V8T 4Y8
  9.  
  10. ===========================================================================
  11.  
  12. INTRODUCTION
  13. ------------
  14.  
  15. The Borland Graphical Interface contains an easy-to-use procedure,
  16. PutImage, for displaying complex images on a portion of the screen.
  17. However, the Turbo C or Pascal programmer faces the difficulty of getting
  18. the image into memory in the first place - that is, of drawing it.
  19.  
  20. CLIP is a bridge between powerful commercial painting programs (such as
  21. Paintbrush and Deluxe Paint II Enhanced) and the BGI. It lets you "clip"
  22. images of any size (up to the 64K limit imposed by PutImage) from PCX files
  23. in EGA and VGA high resolution, and puts these images in files that can be
  24. used by your C or Pascal routines with a minimum of effort.
  25.  
  26.  
  27. OPERATION
  28. ---------
  29.  
  30. The program is very simple to use. First create a PCX graphics file in
  31. 16-color 640x200, 640x350, or 640x480 resolution, using a painting or
  32. screen-capture program. (If your software doesn't directly support the PCX
  33. format, it may include a conversion program that does.) Then run CLIP with
  34. the pathname of the graphics file on the command line; don't include the
  35. ".PCX" part.
  36.  
  37. By default the program will come up in 640x480 resolution if your system
  38. supports it, but you can override this default by entering "/e" on the
  39. command line after the PCX file name, in which case the display mode will
  40. be 640x350 and only EGA palette information will be produced (more on this
  41. below).
  42.  
  43. Now, with the mouse, point to one corner of the image you wish to save.
  44. Hold down the left button and drag the mouse to create a frame around the
  45. image. The area you are defining includes the pixels covered by the frame
  46. lines, so that you can work right to the edge of the screen.
  47.  
  48. When you release the button, you are prompted to enter a name for the image
  49. file. Type the file name and press <Enter>, or abort with <Esc>. You may
  50. use any file name except one with the extension ".PAL".
  51.  
  52. If the image is too large for the BGI PutImage procedure, a bell sounds and
  53. you are not allowed to save. The size limit is about 58 percent of the
  54. screen in EGA mode or about 42 percent in VGA. If you want to save the
  55. entire screen, you can of course do so in chunks; but a better way is to
  56. get PCXPAS.ZIP, which contains a Turbo Pascal unit for the very quick
  57. display of full-screen PCX files in most formats.
  58.  
  59. By default the co-ordinates of the mouse are shown at the upper right
  60. corner of the screen. This information can be useful for cutting images
  61. exactly to size, especially if you have made a note of the desired
  62. boundaries while working in the magnified mode of your painting program. If
  63. you wish to cut an image in this corner of the screen, press <F1> to toggle
  64. off the display of co-ordinates.
  65.  
  66. Continue saving images from the screen until you're done; then press
  67. <Alt-X> or <F10> to exit.
  68.  
  69.  
  70. USING CLIP IMAGES IN TURBO PASCAL AND TURBO C
  71. ---------------------------------------------
  72.  
  73. The data structure used by Borland's image-manipulating procedures and
  74. functions is the same in both Turbo Pascal and Turbo C, and CLIP's
  75. output files are equally usable with either language. The examples in this
  76. section will be in Pascal.
  77.  
  78. The disk file created by CLIP to store an image takes exactly the same
  79. form as the data structure created by the Turbo GetImage procedure and used
  80. by PutImage. It is an untyped file.
  81.  
  82. The first two words in the file store the width and height respectively of
  83. the image (counting from zero: an image of "1 by 1" is actually 2 by 2).
  84. The PutImage procedure uses these figures to set up the image properly, and
  85. they are also used by ImageSize to calculate the storage needed for the
  86. image. The BGI does not use data compression; a blank image occupies as
  87. much storage space as a complex image of the same dimensions.
  88.  
  89. Here is a simple routine to import an image from a file and display it at
  90. the current pointer.
  91.  
  92.   var    BitMap: Pointer;
  93.          f: file;
  94.  
  95.   Begin
  96.     Assign(f, 'MYIMAGE.IM');
  97.     Reset(f, 1);
  98.     GetMem(BitMap, FileSize(f));
  99.     BlockRead(f, BitMap^, FileSize(f));
  100.     PutImage(GetX, GetY, BitMap^, CopyPut);
  101.   End;
  102.  
  103. For a program that uses multiple images, it may be convenient to group all
  104. the images together in a single data file. It is easy to do so with the DOS
  105. Copy command. For example, to create a file "CHESSMEN" containing all the
  106. pieces:
  107.  
  108.   COPY KING/B + QUEEN + BISHOP + KNIGHT + ROOK + PAWN CHESSMEN
  109.  
  110. Note the "/B" argument after the first filename. Do not omit this; it is
  111. essential so that DOS treats all the files as binary and does not truncate
  112. any on encountering a Control-Z.
  113.  
  114. Obviously it is up to the programmer to ensure that the file-reading
  115. routines take into account the number of bytes occupied by each image. If
  116. the file contains images of different sizes that are to be stored
  117. dynamically as they are imported, you can use the ImageSize function to
  118. determine how much memory to allocate for each image:
  119.  
  120.   var   Width, Height, Size: word;
  121.         BitMap: pointer;
  122.         f: file;
  123.  
  124.   Reset(f, 1);
  125.   BlockRead(f, Width, 2);               { Get dimensions from header }
  126.   BlockRead(f, Height, 2);
  127.   Size:= ImageSize(0, 0, Width, Height);
  128.   GetMem(BitMap, Size);
  129.   Seek(f, FilePos(f) - 4);              { Back up }
  130.   BlockRead(f, Bitmap^, Size);          { Get whole image }
  131.  
  132. This routine has the great advantage that you can alter the size of any of
  133. the component images in the file without having to change program code.
  134.  
  135.  
  136. INCORPORATING PALETTE CHANGES
  137. -----------------------------
  138.  
  139. Whenever you save an image file, CLIP automatically creates a palette
  140. file with the same name and the extension ".PAL". If CLIP is running in
  141. EGA (350-line) mode, this is simply an untyped 17-byte file containing a
  142. PaletteType record. For the VGA, it is an array of the RGB values for each
  143. of the 16 palette entries, or 48 bytes in all.
  144.  
  145. If you are working in 350-line mode on the VGA, the program presumes that
  146. you want only EGA palette data. If you want the full VGA information, you
  147. can load the file in 480-line mode; the resulting distortion will make no
  148. difference if the clipped images are ultimately to be displayed in their
  149. original 350-line format.
  150.  
  151. For the EGA, you can easily import saved palette values into your own
  152. program by BlockReading the palette file into a PaletteType variable. It is
  153. then simply a matter of passing that variable into SetAllPalette. (Of
  154. course, in many cases it may be preferable to hard-code the palette values,
  155. which can be examined with DEBUG.)
  156.  
  157. For the VGA, things are a bit more complicated. Here you have to make these
  158. declarations:
  159.  
  160.    type    RGBrec = record
  161.                       redval, greenval, blueval: byte;
  162.                     end;
  163.  
  164.    var     RGBpalette: array[0..15] of RGBrec;
  165.  
  166. Now BlockRead the palette file into RGBpalette. From here the data can be
  167. passed into Turbo's SetRGBPalette procedure; but first you have to make
  168. sure that the palette entries are pointing to the registers you are
  169. modifying. (In the VGA, the 16 palette entries don't contain color values;
  170. they contain the numbers of color registers, which in turn hold the actual
  171. colors.) By default the palette points to registers 0-5, 20, 7, and 56-63,
  172. which contain the standard EGA colors. You can either modify these
  173. registers or else use SetPalette to put the numbers 0-15 in the palette,
  174. then modify registers 0-15 with SetRGBPalette.
  175.  
  176. Files of 640x200 resolution are a special case. If you want to display
  177. images in the BGI "EGALo" format, only the 16 default colors are available,
  178. so it is unlikely you will want any palette information; in any case, the
  179. .PAL file produced by CLIP in its EGA mode will be of no use since the
  180. palette system is completely different in 200-line and 350-line modes. If
  181. you want the full VGA palette data for "VGALo" format, you must create the
  182. image in CLIP's 480-line mode. Again, the distortion will make no
  183. difference in the final product.
  184.  
  185.  
  186. LINKING DATA INTO THE .EXE FILE
  187. -------------------------------
  188.  
  189. For the sake of tidiness you may want to incorporate image and palette data
  190. in the executable file itself rather than keeping it in separate files.
  191. Turbo Pascal makes this easy.
  192.  
  193. Suppose you have an image of an apple in the file MYAPPLE.IM. First convert
  194. this to an object file with Borland's BINOBJ program (distributed with
  195. Turbo Pascal) thus:
  196.  
  197.   BINOBJ MYAPPLE.IM APPLE GETAPPLE
  198.  
  199. There are three arguments on the command line. The first is the source
  200. file, the second is the destination file (.OBJ is assumed), and the third
  201. is the public declaration or interface of the object file. You are creating
  202. APPLE.OBJ, which contains the public declaration GetApple.
  203.  
  204. Now, in your Pascal program, you declare a dummy "procedure" using the
  205. public name of the data, and link in the object file:
  206.  
  207.   procedure GetApple; external;
  208.   {$L APPLE.OBJ}
  209.  
  210. Finally, you declare a pointer variable and assign it the address of the
  211. dummy procedure:
  212.  
  213.   var   AppleImage: pointer;
  214.  
  215.   AppleImage:= @GetApple;
  216.  
  217. And when you want to display the image:
  218.  
  219.   PutImage(GetX, GetY, AppleImage^, CopyPut);
  220.  
  221. Although linked data is convenient, remember that it takes up memory space
  222. for the life of the program, whereas data from files can be read into
  223. dynamic memory and discarded when no longer needed. If memory is in short
  224. supply and an image only has to be written to the screen once, a separate
  225. data file is probably the best choice.
  226.  
  227.  
  228. COPYRIGHT NOTICE
  229. ----------------
  230.  
  231. CLIP was produced with Turbo Pascal and Turbo Assembler, both copyrighted
  232. programs of Borland International.
  233.  
  234. ===========================================================================
  235.  
  236.  
  237.          ----------------end-of-author's-documentation---------------
  238.  
  239.                          Software Library Information:
  240.  
  241.                     This disk copy provided as a service of
  242.  
  243.                            Public (software) Library
  244.  
  245.          We are not the authors of this program, nor are we associated
  246.          with the author in any way other than as a distributor of the
  247.          program in accordance with the author's terms of distribution.
  248.  
  249.          Please direct shareware payments and specific questions about
  250.          this program to the author of the program, whose name appears
  251.          elsewhere in  this documentation. If you have trouble getting
  252.          in touch with the author,  we will do whatever we can to help
  253.          you with your questions. All programs have been tested and do
  254.          run.  To report problems,  please use the form that is in the
  255.          file PROBLEM.DOC on many of our disks or in other written for-
  256.          mat with screen printouts, if possible.  PsL cannot debug pro-
  257.          programs over the telephone, though we can answer questions.
  258.  
  259.          Disks in the PsL are updated  monthly,  so if you did not get
  260.          this disk directly from the PsL, you should be aware that the
  261.          files in this set may no longer be the current versions. Also,
  262.          if you got this disk from another vendor and are having prob-
  263.          lems,  be aware that  some files may have become corrupted or
  264.          lost by that vendor. Get a current, working disk from PsL.
  265.  
  266.          For a copy of the latest monthly software library newsletter
  267.          and a list of the 2,000+ disks in the library, call or write
  268.  
  269.                            Public (software) Library
  270.                                P.O.Box 35705 - F
  271.                             Houston, TX 77235-5705
  272.  
  273.                                 1-800-2424-PSL
  274.                              MC/Visa/AmEx/Discover
  275.  
  276.                           Outside of U.S. or in Texas
  277.                           or for general information,
  278.                               Call 1-713-524-6394
  279.  
  280.                           PsL also has an outstanding
  281.                           catalog for the Macintosh.
  282.  
  283.